home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __version__ = '0.1'
- __title__ = 'Services and Status System Tray Device I/O Child Process'
- __mod__ = 'hpdio'
- __doc__ = 'Provides device I/O process isolation for system tray application.'
- import sys
- import struct
- import os
- import time
- import Queue
- import select
- from cPickle import dumps, HIGHEST_PROTOCOL
- from base.g import *
- from base.codes import *
- from base import utils, device, status, models
-
- try:
- from dbus import lowlevel, SessionBus
- except ImportError:
- log.error('dbus failed to load (python-dbus ver. 0.80+ required). Exiting...')
- sys.exit(1)
-
- PIPE_BUF = 4096
- session_bus = None
- (r2, w3) = (None, None)
- devices = { }
-
- def send_message(device_uri, event_code, bytes_written = 0):
- args = [
- device_uri,
- '',
- event_code,
- prop.username,
- 0,
- '',
- '',
- bytes_written]
- msg = lowlevel.SignalMessage('/', 'com.hplip.StatusService', 'Event')
- msg.append(signature = 'ssisissi', *args)
- SessionBus().send_message(msg)
-
-
- def run(read_pipe2 = None, write_pipe3 = None):
- global r2, w3
- tmp_dir = '/tmp'
- os.umask(73)
-
- try:
- log.set_module('hp-systray(hpdio)')
- log.debug('PID=%d' % os.getpid())
- r2 = read_pipe2
- w3 = write_pipe3
- fmt = '64s64sI32sI64sf'
- fmt_size = struct.calcsize(fmt)
- response = { }
- dev = None
- m = ''
- while True:
-
- try:
- (r, w, e) = select.select([
- r2], [], [
- r2], 1)
- except KeyboardInterrupt:
- break
- except select.error:
- e = None
- if e[0] == errno.EINTR:
- continue
- else:
- break
- except:
- e[0] == errno.EINTR
-
- if not r:
- continue
-
- if e:
- break
-
- m = ''.join([
- m,
- os.read(r2, fmt_size)])
- if not m:
- break
-
- while len(m) >= fmt_size:
- response.clear()
- event = device.Event(*struct.unpack(fmt, m[:fmt_size]))
- m = m[fmt_size:]
- action = event.event_code
- device_uri = event.device_uri
- log.debug('Handling event...')
- event.debug()
- send_message(device_uri, EVENT_DEVICE_UPDATE_ACTIVE)
- if action in (EVENT_DEVICE_UPDATE_REQUESTED, EVENT_POLLING_REQUEST):
-
- try:
- dev = devices[device_uri]
- except KeyError:
- dev = devices[device_uri] = device.Device(device_uri, disable_dbus = True)
-
-
- try:
- dev.open()
- except Error:
- e = None
- log.error(e.msg)
- response = {
- 'error-state': ERROR_STATE_ERROR,
- 'device-state': DEVICE_STATE_NOT_FOUND,
- 'status-code': EVENT_ERROR_DEVICE_IO_ERROR }
-
- if dev.device_state == DEVICE_STATE_NOT_FOUND:
- dev.error_state = ERROR_STATE_ERROR
- elif action == EVENT_DEVICE_UPDATE_REQUESTED:
-
- try:
- dev.queryDevice()
- except Error:
- e = None
- log.error('Query device error (%s).' % e.msg)
- dev.error_state = ERROR_STATE_ERROR
- dev.status_code = EVENT_ERROR_DEVICE_IO_ERROR
-
- response = dev.dq
- log.debug('Device state = %d' % dev.device_state)
- log.debug('Status code = %d' % dev.status_code)
- log.debug('Error state = %d' % dev.error_state)
- else:
-
- try:
- dev.pollDevice()
- except Error:
- e = None
- log.error('Poll device error (%s).' % e.msg)
- dev.error_state = ERROR_STATE_ERROR
-
- response = {
- 'test': 1 }
- if dev is not None:
- dev.close()
-
- elif action == EVENT_USER_CONFIGURATION_CHANGED:
- pass
- elif action == EVENT_SYSTEMTRAY_EXIT:
- log.debug('Exiting')
- sys.exit(1)
-
- send_message(device_uri, EVENT_DEVICE_UPDATE_INACTIVE)
- if action == EVENT_DEVICE_UPDATE_REQUESTED:
- data = dumps(response, HIGHEST_PROTOCOL)
- log.debug('Sending data through pipe to hpssd...')
- total_written = 0
- while True:
- total_written += os.write(w3, data[:PIPE_BUF])
- data = data[PIPE_BUF:]
- if not data:
- break
- continue
- log.debug('Wrote %d bytes' % total_written)
- send_message(device_uri, EVENT_DEVICE_UPDATE_REPLY, total_written)
- continue
- if action == EVENT_POLLING_REQUEST:
- continue
- except KeyboardInterrupt:
- log.debug('Ctrl-C: Exiting...')
-
-
-